#include <iostream>
#include <vector>
#include <math.h>
#include <cstring>
#include <algorithm>
using namespace std;
vector<int> a;
bool vis[1010] = {false};
int n;
bool prime(int x) {
    if (x == 1) return false;
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0) return false;
    }
    return true;
}
int res = 2e9;
void dfs(int pos, int ans) {
    if (pos == n) {
        res = min(res, ans);
        return;
    }
    for (int i = 2; i <= a[pos]; i++) {
        if (a[pos] % i == 0 && prime(i) && !vis[i]) {
            vis[i] = true;
            dfs(pos + 1, ans + i);
            vis[i] = false;
        }
    }
}
int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    dfs(0, 0);
    if (res == 2e9) cout << -1 << endl;
    else cout << res << endl;
    return 0;
}